package com.fandou.airobot.ui.home;

import android.content.Context;

import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.fandou.airobot.R;
import com.fandou.airobot.data.bean.HomeItem;
import com.fandou.airobot.databinding.AiRobotHomeItemLayoutBinding;
import com.fandou.base.ui.adapter.SimpleDataBindingAdapter;

public class HomeItemAdapter extends SimpleDataBindingAdapter<HomeItem, AiRobotHomeItemLayoutBinding> {

    public HomeItemAdapter(Context context, HomeFragment.ClickProxy clickProxy) {
        super(context, R.layout.ai_robot_home_item_layout, new DiffUtil.ItemCallback<HomeItem>() {
            @Override
            public boolean areItemsTheSame(HomeItem oldItem, HomeItem newItem) {
                return oldItem.equals(newItem);
            }

            @Override
            public boolean areContentsTheSame(HomeItem oldItem, HomeItem newItem) {
                return oldItem.getTitle().equals(newItem.getTitle());
            }
        });

        setOnItemClickListener((item, position) -> clickProxy.clickItem(item));
    }

    @Override
    protected void onBindItem(AiRobotHomeItemLayoutBinding binding, HomeItem item, RecyclerView.ViewHolder holder) {
        binding.setHomeItem(item);
    }
}
